/************************************************************************************
**  
* @copyright (c) 2015-, Technology Co., LTD. All Right Reserved.
*
*************************************************************************************/
/**
* @file     duye_cap_transfer.h
* @version     
* @brief      
* @author   
* @date     2013-04-09
* @note 
*
*  1. 2018-04-09 created this file
* 
*/
#pragma once

#include <list>
#include <duye_type.h>
#include <duye_socket.h>
#include <duye_cap_protocol.h>

namespace duye {

/**
 * @brief class module message
 * @note
 */
class ModuleMsg {
public:
	ModuleMsg();
	explicit ModuleMsg(const std::string& msgName, const uint32 msgId = 0);
	~ModuleMsg();

	void setMsgId(const uint32 id);
	uint32 getMsgId() const;

	void setMsgName(const std::string& name);
	const std::string& getMsgName() const;

	void setData(const int8* data, const uint32 size);
	const int8* getData() const;
	uint32 getDataSize() const;

private:
	uint32 m_msgId;
	std::string m_msgName;
	int8* m_data;
	uint32 m_size;
};

/*
 * @brief network transfer class
 */
// class NetTransfer {
// public:
// 	NetTransfer();
// 	NetTransfer(const ProtocolType protoType);
// 	~NetTransfer();

// 	/**
// 	 * @brief set transfer type
// 	 * @param [in] protoType : protocol type
// 	 */
// 	void setTransferProto(const ProtocolType protoType);

// 	/**
// 	 * @brief send data to remote
// 	 * @param [in] data : data
// 	 * @param [in] size : data size
// 	 * @return sent size, -1 indicate failed
// 	 */
// 	int32 send(const int8* data, const uint32 size);

// 	/**
// 	 * @brief received data
// 	 * @param [in] recvBuf : receive buffer
// 	 * @param [in] bufSize : receive buffer size
// 	 * @param [in] timeout : timeout, millisecond, default is 0 indicate die waiting
// 	 * @return received size, -1 failed
// 	 */
// 	int32 recv(int8* recvBuf, const uint32 bufSize);
// 	int32 recv(int8* recvBuf, const uint32 bufSize, const uint32 timeout);

// 	/**
// 	 * @brief set remote address
// 	 * @param [in] ip : ip address
// 	 * @param [in] port : port
// 	 */
// 	void setRemoteAddr(const uint32 ip, const uint16 port);
// 	uint32 getRemoteIP() const;

// 	/**
// 	 * @brief set local address
// 	 * @param [in] ip : ip address
// 	 * @param [in] port : port
// 	 */
// 	void setLocalAddr(const uint32 ip, const uint16 port);
// 	uint32 getLocalIP() const;

// 	/**
// 	 * @brief connect remote server
// 	 * @return true/false
// 	 */
// 	bool connect();

// 	// close connect
// 	bool close();

// private:
// 	// create ClientInterface
// 	bool createClient();

// private:
// 	ClientInterface* m_client;
// 	uint32 m_remoteIP;
// 	uint16 m_remotePort;
// 	uint32 m_localIP;
// 	uint16 m_localPort;
// 	bool m_isConnect;
// 	packet::ProtocolType m_protoType;
// };

/**
 * @brief class receiver interface
 * @note
 */
class RecverInterface {
public:
	virtual ~RecverInterface() {}

	/**
	 * @brief receiver callback
	 * @param [in] msg : received message
	 * @return 0
	 * @note
	 */
	virtual int32 recv(const ModuleMsg& msg) = 0;
};

typedef std::list<RecverInterface*> RecverList;

/**
 * @brief module transfer class
 */
class ModuleTransfer {
public:
	ModuleTransfer();
	virtual ~ModuleTransfer();

	/**
	 * @brief send message
	 * @param [in] msg : send message
	 * @return
	 * @note
	 */
	bool send(const ModuleMsg& msg);

	/**
	 * @brief add receiver
	 * @param [in] recver : receiver object
	 * @return
	 * @note
	 */
	void addRecver(RecverInterface* recver);

private:
	RecverList m_recverList;
};

}
